/*
 * @Author: zi.yang
 * @Date: 2022-02-07 20:04:37
 * @LastEditors: zi.yang
 * @LastEditTime: 2022-02-07 23:08:41
 * @Description: In User Settings Edit
 * @FilePath: \api-generator\app\middleware\upload_dir.js
 */
'use strict';

const fs = require('fs');

module.exports = () => {
  return async function uploadDir(ctx, next) {
    await next();
    try {
      const dirExists = fs.existsSync(ctx.uploadPath);
      if (!dirExists) {
        fs.mkdirSync(ctx.uploadPath);
      }
    } catch (e) {
      ctx.logger.error(e);
    }
  };
};
